package gmusic.command;

import gmusic.bo.ArtistBean;
import gmusic.bo.ReleaseBean;
import gmusic.ma.services.impl.MetalArchivesServicesImpl;
import gmusic.mb.services.impl.MusicBrainzServicesImpl;
import gmusic.services.impl.GMusicServicesImpl;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class Accueil implements Command {

	// private final static Logger log = Logger.getLogger(Accueil.class);

	public String execute(HttpServletRequest req) throws Exception {

		HttpSession session = req.getSession();

		List<ArtistBean> lastArtists = GMusicServicesImpl.getInstance()
				.getLastArtists(10);
		List<ReleaseBean> lastReleases = GMusicServicesImpl.getInstance()
				.getLastReleases(10);

		int nbArtistsGM = GMusicServicesImpl.getInstance().getNbArtists();
		int nbReleasesGM = GMusicServicesImpl.getInstance().getNbReleases();
		int nbTracksGM = GMusicServicesImpl.getInstance().getNbTracks();

		int nbArtistsMA = MetalArchivesServicesImpl.getInstance()
				.getNbArtists();
		int nbReleasesMA = MetalArchivesServicesImpl.getInstance()
				.getNbReleases();
		int nbTracksMA = MetalArchivesServicesImpl.getInstance().getNbTracks();

		int nbArtistsMB = MusicBrainzServicesImpl.getInstance().getNbArtists();
		int nbReleasesMB = MusicBrainzServicesImpl.getInstance()
				.getNbReleases();
		int nbTracksMB = MusicBrainzServicesImpl.getInstance().getNbTracks();

		session.setAttribute("lastArtists", lastArtists);
		session.setAttribute("lastReleases", lastReleases);
		session.setAttribute("nbArtistsGM", new Integer(nbArtistsGM));
		session.setAttribute("nbReleasesGM", new Integer(nbReleasesGM));
		session.setAttribute("nbTracksGM", new Integer(nbTracksGM));
		session.setAttribute("nbArtistsMA", new Integer(nbArtistsMA));
		session.setAttribute("nbReleasesMA", new Integer(nbReleasesMA));
		session.setAttribute("nbTracksMA", new Integer(nbTracksMA));
		session.setAttribute("nbArtistsMB", new Integer(nbArtistsMB));
		session.setAttribute("nbReleasesMB", new Integer(nbReleasesMB));
		session.setAttribute("nbTracksMB", new Integer(nbTracksMB));

		return "/index.jsp";
	}
}
